﻿using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using Orchard.Localization;
using TissotWeb.HeadFoot.Models;

namespace TissotWeb.HeadFoot.Drivers {
	public class HeadFootSettingsPartDriver : ContentPartDriver<HeadFootSettingsPart> {
        private const string TemplateName = "Parts/HeadFootSettings";

        public HeadFootSettingsPartDriver()
        {
			T = NullLocalizer.Instance;
		}

		public Localizer T { get; set; }

        protected override string Prefix { get { return "HeadFootSettings"; } }
		
		//GET
        protected override DriverResult Editor(HeadFootSettingsPart part, dynamic shapeHelper)
        {
            return ContentShape("Parts_HeadFootSettings_Edit",
					() => shapeHelper.EditorTemplate(
						TemplateName: TemplateName,
						Model: part,
						Prefix: Prefix)).OnGroup("Header Footer Hooks");
		}

		//POST
        protected override DriverResult Editor(HeadFootSettingsPart part, IUpdateModel updater, dynamic shapeHelper)
        {
			updater.TryUpdateModel(part, Prefix, null, null);
			return Editor(part, shapeHelper);
		}
	}
}